package com.dynamixsoftware.printershare;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import com.dynamixsoftware.printershare.data.Printer;
import com.dynamixsoftware.printershare.data.SoapEnvelope;
import com.dynamixsoftware.printershare.data.SoapService;
import com.dynamixsoftware.printershare.data.User;
import com.dynamixsoftware.printershare.data.XmlUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.w3c.dom.Element;

public class ActivityPrinters
  extends ActivityCore
{
  private static final int DIALOG_OWNER_DETAILS = 2;
  private static final int DIALOG_PRINTER_DETAILS = 1;
  private Thread rt;
  private View view_dialog_owner_details;
  private View view_dialog_printer_details;
  
  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    if (paramInt1 == 2)
    {
      PrinterAdapter localPrinterAdapter = (PrinterAdapter)((ListView)findViewById(2131230809)).getAdapter();
      if (localPrinterAdapter != null) {
        localPrinterAdapter.fireOnChanged();
      }
      if (paramInt2 == -1) {
        setResult(-1);
      }
    }
  }
  
  public boolean onContextItemSelected(MenuItem paramMenuItem)
  {
    switch (paramMenuItem.getItemId())
    {
    default: 
      return false;
    case 51: 
      AdapterView.AdapterContextMenuInfo localAdapterContextMenuInfo2 = (AdapterView.AdapterContextMenuInfo)paramMenuItem.getMenuInfo();
      Printer localPrinter2 = (Printer)remote_printers.elementAt(localAdapterContextMenuInfo2.position);
      ((TextView)this.view_dialog_printer_details.findViewById(2131230758)).setText(localPrinter2.title);
      ((TextView)this.view_dialog_printer_details.findViewById(2131230759)).setText(localPrinter2.location);
      TextView localTextView = (TextView)this.view_dialog_printer_details.findViewById(2131230760);
      if (localPrinter2.online) {}
      for (String str = "Online";; str = "Offline")
      {
        localTextView.setText(str);
        showDialog(1);
        return true;
      }
    case 52: 
      AdapterView.AdapterContextMenuInfo localAdapterContextMenuInfo1 = (AdapterView.AdapterContextMenuInfo)paramMenuItem.getMenuInfo();
      Printer localPrinter1 = (Printer)remote_printers.elementAt(localAdapterContextMenuInfo1.position);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230743)).setText(localPrinter1.owner.login);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230744)).setText(localPrinter1.owner.name);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230745)).setText(localPrinter1.owner.nick);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230746)).setText(localPrinter1.owner.email);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230747)).setText(localPrinter1.owner.phone);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230748)).setText(localPrinter1.owner.address);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230749)).setText(localPrinter1.owner.city + " " + localPrinter1.owner.state + " " + localPrinter1.owner.zip);
      ((TextView)this.view_dialog_owner_details.findViewById(2131230750)).setText(localPrinter1.owner.country);
      showDialog(2);
      return true;
    }
    this.rt = new RemovePrinterThread(((AdapterView.AdapterContextMenuInfo)paramMenuItem.getMenuInfo()).position);
    this.rt.start();
    return true;
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903067);
    setTitle(2131099673);
    LayoutInflater localLayoutInflater = LayoutInflater.from(this);
    this.view_dialog_printer_details = localLayoutInflater.inflate(2130903049, null);
    this.view_dialog_owner_details = localLayoutInflater.inflate(2130903047, null);
    ((Button)findViewById(2131230807)).setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        Intent localIntent = new Intent();
        localIntent.setClass(ActivityPrinters.this, ActivityFindPrinters.class);
        ActivityPrinters.this.startActivityForResult(localIntent, 2);
      }
    });
    ((Button)findViewById(2131230808)).setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        Intent localIntent = new Intent();
        localIntent.setClass(ActivityPrinters.this, ActivityProfile.class);
        ActivityPrinters.this.startActivity(localIntent);
      }
    });
    ListView localListView = (ListView)findViewById(2131230809);
    localListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
      public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        for (int i = 0;; i++) {
          if (i < paramAnonymousAdapterView.getChildCount())
          {
            View localView = paramAnonymousAdapterView.getChildAt(i);
            if (ActivityCore.printer == localView.getTag()) {
              localView.findViewById(2131230801).setVisibility(4);
            }
          }
          else
          {
            paramAnonymousView.findViewById(2131230801).setVisibility(0);
            ActivityPrinters.this.setPrinter((Printer)paramAnonymousView.getTag());
            ActivityPrinters.this.setResult(-1);
            ActivityPrinters.this.finish();
            return;
          }
        }
      }
    });
    registerForContextMenu(localListView);
  }
  
  public void onCreateContextMenu(ContextMenu paramContextMenu, View paramView, ContextMenu.ContextMenuInfo paramContextMenuInfo)
  {
    paramContextMenu.setHeaderTitle(2131099765);
    paramContextMenu.add(0, 51, 0, 2131099766);
    paramContextMenu.add(0, 52, 0, 2131099767);
    paramContextMenu.add(0, 53, 0, 2131099768);
  }
  
  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default: 
      return null;
    case 1: 
      new AlertDialog.Builder(this).setIcon(17301659).setTitle(2131099766).setView(this.view_dialog_printer_details).setPositiveButton(2131099703, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {}
      }).create();
    }
    new AlertDialog.Builder(this).setIcon(17301659).setTitle(2131099767).setView(this.view_dialog_owner_details).setPositiveButton(2131099703, new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt) {}
    }).create();
  }
  
  protected void update()
  {
    super.update();
    if (remote_printers != null)
    {
      ListView localListView = (ListView)findViewById(2131230809);
      if (localListView.getAdapter() == null) {
        localListView.setAdapter(new PrinterAdapter(this));
      }
    }
  }
  
  class PrinterAdapter
    implements ListAdapter
  {
    public Context mContext;
    private List<DataSetObserver> observers = null;
    
    public PrinterAdapter(Context paramContext)
    {
      this.mContext = paramContext;
    }
    
    public boolean areAllItemsEnabled()
    {
      return true;
    }
    
    public void fireOnChanged()
    {
      if (this.observers != null)
      {
        int i = this.observers.size();
        for (int j = 0; j < i; j++) {
          ((DataSetObserver)this.observers.get(j)).onChanged();
        }
      }
    }
    
    public int getCount()
    {
      return ActivityCore.remote_printers.size();
    }
    
    public Object getItem(int paramInt)
    {
      return ActivityCore.remote_printers.elementAt(paramInt);
    }
    
    public long getItemId(int paramInt)
    {
      return paramInt;
    }
    
    public int getItemViewType(int paramInt)
    {
      return 1;
    }
    
    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      View localView1 = LayoutInflater.from(this.mContext).inflate(2130903064, null);
      Printer localPrinter = (Printer)ActivityCore.remote_printers.elementAt(paramInt);
      ImageView localImageView = (ImageView)localView1.findViewById(2131230760);
      int i;
      String str2;
      label212:
      String str3;
      String str5;
      label327:
      label344:
      int j;
      label397:
      View localView2;
      int k;
      if (localPrinter.online)
      {
        i = 2130837561;
        localImageView.setBackgroundResource(i);
        TextView localTextView1 = (TextView)localView1.findViewById(2131230800);
        String str1 = "[" + localPrinter.owner.login + "]";
        if ((localPrinter.owner.nick != null) && (localPrinter.owner.nick.length() > 0)) {
          str1 = localPrinter.owner.nick;
        }
        if ((localPrinter.owner.name != null) && (localPrinter.owner.name.length() > 0)) {
          str1 = localPrinter.owner.name;
        }
        localTextView1.setText(str1);
        TextView localTextView2 = (TextView)localView1.findViewById(2131230758);
        if ((localPrinter == null) || (localPrinter.title == null)) {
          break label476;
        }
        str2 = localPrinter.title;
        localTextView2.setText(str2);
        TextView localTextView3 = (TextView)localView1.findViewById(2131230759);
        str3 = "";
        if ((localPrinter.owner.country != null) && (localPrinter.owner.country.length() > 0)) {
          str3 = localPrinter.owner.country;
        }
        if ((localPrinter.owner.city == null) || (localPrinter.owner.city.length() <= 0)) {
          break label490;
        }
        StringBuilder localStringBuilder2 = new StringBuilder().append(localPrinter.owner.city);
        if (str3.length() <= 0) {
          break label483;
        }
        str5 = ", ";
        str3 = str5 + str3;
        if ((localPrinter.location != null) && (localPrinter.location.length() > 0)) {
          str3 = localPrinter.location;
        }
        if (str3 == null) {
          str3 = "";
        }
        localTextView3.setText(str3);
        if (str3.length() <= 0) {
          break label574;
        }
        j = 0;
        localTextView3.setVisibility(j);
        localView2 = localView1.findViewById(2131230801);
        if ((ActivityCore.printer == null) || (ActivityCore.printer.id == null)) {
          break label581;
        }
        boolean bool = ActivityCore.printer.id.equals(localPrinter.id);
        k = 0;
        if (!bool) {
          break label581;
        }
      }
      for (;;)
      {
        localView2.setVisibility(k);
        localView1.setTag(localPrinter);
        return localView1;
        i = 2130837560;
        break;
        label476:
        str2 = "";
        break label212;
        label483:
        str5 = "";
        break label327;
        label490:
        if ((localPrinter.owner.state == null) || (localPrinter.owner.state.length() <= 0)) {
          break label344;
        }
        StringBuilder localStringBuilder1 = new StringBuilder().append(localPrinter.owner.state);
        if (str3.length() > 0) {}
        for (String str4 = ", ";; str4 = "")
        {
          str3 = str4 + str3;
          break;
        }
        label574:
        j = 8;
        break label397;
        label581:
        k = 4;
      }
    }
    
    public int getViewTypeCount()
    {
      return 1;
    }
    
    public boolean hasStableIds()
    {
      return false;
    }
    
    public boolean isEmpty()
    {
      return ActivityCore.remote_printers.size() == 0;
    }
    
    public boolean isEnabled(int paramInt)
    {
      return true;
    }
    
    public void registerDataSetObserver(DataSetObserver paramDataSetObserver)
    {
      if (this.observers == null) {
        this.observers = new ArrayList();
      }
      if (!this.observers.contains(paramDataSetObserver)) {
        this.observers.add(paramDataSetObserver);
      }
    }
    
    public void unregisterDataSetObserver(DataSetObserver paramDataSetObserver)
    {
      if (this.observers == null) {
        return;
      }
      this.observers.remove(paramDataSetObserver);
    }
  }
  
  class RemovePrinterThread
    extends Thread
  {
    private Printer prn;
    
    public RemovePrinterThread(int paramInt)
    {
      this.prn = ((Printer)ActivityCore.remote_printers.elementAt(paramInt));
    }
    
    public void run()
    {
      ActivityPrinters.this.runOnUiThread(new Runnable()
      {
        public void run()
        {
          ActivityPrinters.this.showProgress(ActivityPrinters.this.getResources().getString(2131099746));
        }
      });
      ActivityPrinters.this.last_error = null;
      for (;;)
      {
        try
        {
          SoapEnvelope localSoapEnvelope = new SoapEnvelope("ChangePrinters", "Param", "data");
          Element localElement1 = localSoapEnvelope.getDataRoot();
          XmlUtil.appendElement(localElement1, "token", ActivityCore.token);
          localElement1.setAttribute("action", "dislike");
          XmlUtil.appendElement(XmlUtil.appendElement(localElement1, "printer"), "public-id", this.prn.id);
          localElement2 = ActivityPrinters.this.psService.doAction(localSoapEnvelope).getDataRoot();
          if (!"true".equals(localElement2.getAttribute("success"))) {
            continue;
          }
          ActivityCore.remote_printers.remove(this.prn);
          if (ActivityCore.printer == this.prn)
          {
            ActivityPrinters localActivityPrinters = ActivityPrinters.this;
            if (ActivityCore.remote_printers.size() <= 0) {
              continue;
            }
            localPrinter = (Printer)ActivityCore.remote_printers.elementAt(0);
            localActivityPrinters.setPrinter(localPrinter);
            ActivityPrinters.this.setResult(-1);
          }
        }
        catch (Exception localException)
        {
          Element localElement2;
          Printer localPrinter;
          localException.printStackTrace();
          ActivityPrinters.this.last_error = ("Internal Error: " + localException.getMessage());
          App.reportThrowable(localException);
          continue;
          ActivityPrinters.this.runOnUiThread(new Runnable()
          {
            public void run()
            {
              ActivityPrinters.this.hideProgress();
              ActivityPrinters.this.displayLastError(new DialogInterface.OnClickListener()
              {
                public void onClick(DialogInterface paramAnonymous2DialogInterface, int paramAnonymous2Int) {}
              });
            }
          });
          continue;
        }
        if (ActivityPrinters.this.last_error != null) {
          continue;
        }
        ActivityPrinters.this.runOnUiThread(new Runnable()
        {
          public void run()
          {
            ActivityPrinters.this.hideProgress();
            ((ActivityPrinters.PrinterAdapter)((ListView)ActivityPrinters.this.findViewById(2131230809)).getAdapter()).fireOnChanged();
          }
        });
        ActivityPrinters.access$002(ActivityPrinters.this, null);
        return;
        localPrinter = null;
        continue;
        ActivityPrinters.this.last_error = ("Error: " + XmlUtil.getFirstNodeValue(localElement2, "message"));
      }
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.ActivityPrinters
 * JD-Core Version:    0.7.0.1
 */